package cn.edu.neu.controller.manage;

import cn.edu.neu.model.Reported;
import cn.edu.neu.model.ScenicSpot;
import cn.edu.neu.model.TravelNotes;
import cn.edu.neu.model.User;
import cn.edu.neu.service.ReportedService;
import cn.edu.neu.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping("/solve")
public class SolveReportedController {
    @Autowired
    private ReportedService reportedService;
    @Autowired
    private UserService userService;
    @RequestMapping("/getReportedList")
    public String getReportedList(Model model){
        List<Reported> reportedList =reportedService.getReportedList();
        model.addAttribute("reported",reportedList);
        return "/manage/reported/reported";
    }
    @RequestMapping("/getReportedByUserIdAndId/{id}/{userId}")
    public String getReportedByUserIdAndId(@PathVariable("id") Integer id,
                                           @PathVariable("userId")Integer user_id,Model model){
        Reported reported=reportedService.getReportedById(id);
        User user=userService.getUserById(user_id);
        model.addAttribute("reported",reported) ;
        model.addAttribute("user",user) ;
        return "/manage/reported/solve-reported";
    }
    @RequestMapping("updateStatusYes/{id}")
    public String updateStatusYes(@PathVariable("id") Integer id){
        reportedService.updateStatusYes(id);
        // 根据报告的用户ID更新用户状态为1
        Reported reported = reportedService.getReportedById(id);
        userService.updateUserStatus(reported.getUser_reported_id(), 1);
        return  "redirect:/solve/getReportedList";
    }

    @RequestMapping("updateStatusNo/{id}")
    public String updateStatusNo(@PathVariable("id") Integer id){
        reportedService.updateStatusNo(id);
        return  "redirect:/solve/getReportedList";
    }

}
